const remote = require('electron').remote;
const BrowserWindow = remote.BrowserWindow;

//关闭当前窗口
function onClick_Close(){
    const win = remote.getCurrentWindow();
    win.close();
}

//窗口多窗口
function onClick_createMultiWindows() {
    if (global.windows == undefined){
        //初始化windows数组
        global.windows = []
    }

    var win = new BrowserWindow({
        show:false,
        x:10,y:20,
        width:400,
        height:400,
        backgroundColor:'#2e2c39'
    })
    global.windows.push(win)
    win.loadFile('./child.html')
    win.on('ready-to-show',()=>{
        win.show()
    })
}

//创建子窗口
function onClick_createSubWin(){
    let top = remote.getCurrentWindow();
    let child = new BrowserWindow({
        parent:top,
        width:500,
        height:300,
        show:false,
        backgroundColor: '#3c88df',
        modal:true //模态窗口
    });
    child.loadFile('./child.html');
    child.on('ready-to-show',()=>{
        child.show();
    })

    // top.show();
}

//关闭所有的窗口（除了主窗口）
function onClick_CloseAllWindows() {
    if (global.windows != undefined){
        //扫描并关闭除了主窗口意外的
        for(var i=0;i<global.windows.length;i++){
            global.windows[i].close();
        }
        global.windows.length = 0;
        global.windows = undefined;
    }
}

